<?php
session_start();
include('inc.db.php');

$kostena = $_SESSION['aantalA'] * 2;
$kostenb = $_SESSION['aantalB'] * 5;
$kostenc = $_SESSION['aantalC'] * 6;
$kostend = $_SESSION['aantalD'] * 7;
$kostene = $_SESSION['aantalE'] * 4;


if(!$_SESSION['aantalA']){
	$input1 = '';
	}else{
	$input1 = '<p>'.$_SESSION['aantalA'].'x Product A a 2 euro =  '.$kostena.' Euro</p>';
}
if(!$_SESSION['aantalB']){	
	$input2 = '';
	}else{
	$input2 = '<p>'.$_SESSION['aantalB'].'x Product A a 5 euro =  '.$kostenb.' Euro</p>';	
}
if(!$_SESSION['aantalC']){
	$input3 = '';
	}else{
	$input3 = '<p>'.$_SESSION['aantalC'].'x Product A a 6 euro =  '.$kostenc.' Euro</p>';
}
if(!$_SESSION['aantalD']){
	$input4 = ''; 
	}else{
	$input4 = '<p>'.$_SESSION['aantalD'].'x Product A a 7 euro =  '.$kostend.' Euro</p>'; 	
}
	if(!$_SESSION['aantalE']){
	$input5 = '';
	}else{
	$input5 = '<p>'.$_SESSION['aantalE'].'x Product A a 4 euro =  '.$kostene.' Euro</p>';
}

$totaal = $kostena + $kostenb + $kostenc + $kostend + $kostene;

echo '<h2> Bevestig uw bestelling </h2>';
	  echo $input1;
	  echo $input2;
	  echo $input3;
	  echo $input4;
	  echo $input5;
echo  '<h3> Totaal = '.$totaal.' Euro</h3>';

echo '<form action="bestelling.php" method="post">
	  	<label>Email:</label><input type="email" name="email"/>
		<input type="submit" name="afronden" value="BESTEL!"/>
	 </form>';
	 
if(isset($_POST['afronden'])){
	
	$datum = date('Y:m:d');
	$_SESSION['email'] = $_POST['email'];
	if(!$_SESSION['email']){
		echo '<p style=color:#f00;>Geen email ingevuld</p>';
	}else{
	mysql_query("INSERT INTO bestellingen SET 
				producta='".mysql_real_escape_string($_SESSION['aantalA'])."',
				productb='".mysql_real_escape_string($_SESSION['aantalB'])."',
				productc='".mysql_real_escape_string($_SESSION['aantalC'])."', 
				productd='".mysql_real_escape_string($_SESSION['aantalD'])."',
				producte='".mysql_real_escape_string($_SESSION['aantalE'])."',
				email='".mysql_real_escape_string($_SESSION['email'])."', 
				totaalprijs='".mysql_real_escape_string($totaal)."',
				datum='".mysql_real_escape_string($datum)."'");
				
				$query = mysql_query("SELECT id FROM bestellingen WHERE email='".$_SESSION['email']."'") or die (mysql_error());

			
	while($row = mysql_fetch_array($query))
		{
			$bestelling[] = $row;	
		}				
	echo '<h1> Bedankt voor uw bestelling </h1>';
	echo '<h4> uw bestelnummers zijn/is </h4>';
	foreach($bestelling as $value => $key){
		echo 'Nummer: '.$key[0].'</br>';
	}
	
	
	}
	
}
?>